// router.js
import {
	RouterMount,
	createRouter
} from 'uni-simple-router';
import store from '@/store';
const router = createRouter({
	encodeURI: false,
	platform: process.env.VUE_APP_PLATFORM,
	routes: ROUTES,
	 // 添加跳转间隔
	 navigateInterval: 300 // 单位ms
});
const whiteList = ['/pages/login/login', '/pages/login/regInfo', '/pages/login/reg', '/pages/index/index',
	'/pages/mine/mine'
];

function hasPerm(permslist, prem) {
	let flag = false;
	console.log('prem', prem)
	for (var i = 0; i < prem.length; i++) {
		if (permslist.includes(prem[i])) {
			flag = true;
			break;
		}
	}
	return flag;
}
//全局路由前置守卫
router.beforeEach((to, from, next) => {
	console.log(to, store.state.isLogin);
	next();
	return 
	/* 判断是否登录成功 */
	if (store.state.isLogin) {
		// store.dispatch('getPreMenu')
		// 	.then((permslist) => {
		// 		//目前还没有小程序菜单，所以不做路由拦截
		// 		next();
		// 	})
		next();
	} else {
		if (whiteList.indexOf(to.path) !== -1) {
			// 在免登录白名单，直接进入
			next()
		} else {
			next({
				path: '/pages/login/login',
				NAVTYPE: 'replaceAll',
				query: {
					redirect: to.fullPath
				}
			})
		}

	}

});
// 全局路由后置守卫
router.afterEach((to, from) => {
	console.log('跳转结束', to, from)
})
export {
	router,
	RouterMount
}